<?php 
namespace app\admin\controller;

// use think\Controller;;
use think\Db;

	class ChangeorderController 
	{

			function change_order_status(){
					$wheret['end_time']=array('lt',date("Y-m-d H:i:s"));
					$list=db('spaceOrder')->where($wheret)->where(array('lease_status'=>0))->order('create_time asc')->field('id')->limit(5)->select();		
					foreach ($list as $key => $value) {
						db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'lease_status'=>2));
					}



                    $list=Db::name('spaceOrder')->order('create_time asc')->field('id')->limit(5)->select();
					$now_time=date('Y-m-d');
		
					foreach ($list as $key => $value) {

						$result=db('rent')->field('cycle_time')->where(array('order_id'=>$value['id'],'status'=>2))->find();
						

						if($result){
							$rent_time=explode('---', $result['cycle_time']);
							if($now_time>=$rent_time[0] && $now_time <= $rent_time[1]){
								db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'current_price_status'=>1));
							}else{
								db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'current_price_status'=>0));
							}
						}else{

							db('spaceOrder')->where('id',$value['id'])->update(array('create_time'=>date("Y-m-d H:i:s"),'current_price_status'=>0));

						}
					}	







					$time = time();
					$condition = ' end_time <= "'.$time.'" and audit_status =1 ';
					$infos=db('site_apply_info')->where($condition)->field('id')->select();
					foreach ($infos as $key => $value) {
						
						$throw['audit_status']=3;
						$throw['audit_remark']='审核失败';
						$uninfo=db('site_apply_info')->alias('s')->join('site t','s.site_id=t.id')->join('staff_member m','m.id=s.staff_id')->where('s.id',$value['id'])->field('s.site_id,m.staff_name,t.site_name,s.start_time,s.end_time,m.app_userid')->find();
						db('site_apply_info')->where('id',$value['id'])->update($throw);
						$first='您的会议预约未通过';
						$keyword1 = $uninfo['staff_name'];
						$keyword2 = $uninfo['site_name'];
						$keyword3 = date("Y-m-d H:i",$uninfo['start_time']).'--'.date("Y-m-d H:i",$uninfo['end_time']);
						$remark = '不要灰心，下次留给您最好，欢迎再次预定';
						$url = config('gz_send_templete');
						$appid =config('wx_app_id');
						$pagepath = config('wx_pagepath');
						$return_info = push_wx_info($uninfo['app_userid'],$first,$keyword1,$keyword2,$keyword3,$remark,$url,'',$appid,$pagepath);
					}	














		    }














// */1 * * * *  curl -i  http://erp.crejoy.cn/admin/Changeorder/change_order_status














	}










































	?>
